import copy

import codecs

import requests


class MockTask(object):
    def __init__(self, metadata=None):
        self.metadata = metadata
        self.parent_result = {}
        self.tags = {}
        self.url = "http://mock"

    def copy_tags(self, tags=None):
        if tags is None:
            tags = dict()
        return {**copy.deepcopy(self.tags), **tags}

    def copy_metadata(self, items=None):
        if items is None:
            items = dict()
        return {**copy.deepcopy(self.metadata), **items}


class MockSpider(object):
    def __init__(self, current_task):
        self.current_task = current_task


class MockResponse(object):
    def __init__(self, file_path):
        self.url = file_path
        with codecs.open(file_path, mode='r', encoding='utf-8') as opened_file:
            lines = opened_file.readlines()
            self.content = "".join(lines)


class MockRequest(object):
    def __init__(self):
        self.header = {
            'Connection': 'Keep-Alive',
            'Accept': 'text/html, application/xhtml+xml, */*',
            'Accept-Language': 'en-US,en;q=0.8,zh-Hans-CN;q=0.5,zh-Hans;q=0.3',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36',
        }

    def call(self, url):
        # cookie_str = 'xxx'
        # cookies = dict(map(lambda x: x.split('=', 1), cookie_str.split(";")))
        # return requests.request("GET", url, timeout=10, cookies=cookies, headers=self.header)
        return requests.request("GET", url, timeout=10, headers=self.header)

if __name__ == "__main__":
    url = "https://www.amazon.com/Best-Sellers/zgbs/amazon-devices/ref=zg_bs_nav_0"
    url = "https://www.amazon.com/Best-Sellers-Baby-Bibs-Burp-Cloths/zgbs/baby-products/7874755011/ref=zg_bs_pg_2?_encoding=UTF8&pg=2"
    url = "https://www.amazon.com/dp/B07ZVXDY83/ref=sspa_dk_detail_2?psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUExUTA4UThLMThWU1JKJmVuY3J5cHRlZElkPUEwNjc3MzMzUFBFWFhQTjMyQlpWJmVuY3J5cHRlZEFkSWQ9QTAyOTQwNjczM05GVUFORFc0VkRDJndpZGdldE5hbWU9c3BfZGV0YWlsMiZhY3Rpb249Y2xpY2tSZWRpcmVjdCZkb05vdExvZ0NsaWNrPXRydWU="
    url = "https://www.amazon.com/dp/B06ZXSDRWZ/ref=sspa_dk_detail_4?psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUEzQTZBOUhDWTc4NU1OJmVuY3J5cHRlZElkPUEwNDEwNDQ4MjQ3VUZLRlc2MzlUSCZlbmNyeXB0ZWRBZElkPUEwNjE3NTgzMkk1UjQ0WVNVQTdYSyZ3aWRnZXROYW1lPXNwX2RldGFpbDImYWN0aW9uPWNsaWNrUmVkaXJlY3QmZG9Ob3RMb2dDbGljaz10cnVl"
    url = "https://www.amazon.com/hz/reviews-render/ajax/lazy-widgets/stream?asin=B07C77FSSV&language=en_US&lazyWidget=cr-summarization-attributes&lazyWidget=cr-age-recommendation&lazyWidget=cr-solicitation&lazyWidget=cr-summarization-lighthut"
    response = MockRequest().call(url)
    content = response.content
    print(content)
